//
//  SearchPolicyListVC.m
//  NtoccShipper
//
//  Created by mac on 2019/11/20.
//  Copyright © 2019 zhuchongjin. All rights reserved.
//

#import "SearchPolicyListVC.h"

@interface SearchPolicyListVC ()
@property (nonatomic,strong) CJTextField *fieldSourcesOrderNum;
@property (nonatomic,strong) CJTextField *fieldTranSportOrderNum;
@property (nonatomic,strong) CJTextField *fieldPolicyNum;
@property (nonatomic,strong) CJTextField *fieldStartTime;
@property (nonatomic,strong) CJTextField *fieldEndTime;
@property (nonatomic,copy) NSString *strStartTime;
@property (nonatomic,copy) NSString *strEndTime;
@property (nonatomic,strong) CJTextField *fieldShipperInfo;
@property (nonatomic,strong) CJTextField *fieldDriverInfo;
@end

@implementation SearchPolicyListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setTitleName:@"保单搜索"];
    [self setBackLeftButton:@""];
    [self createTopView];
    [self setDefault];
}
- (void)setDefault{
    self.fieldSourcesOrderNum.text = @"";
    self.fieldTranSportOrderNum.text = @"";
    self.fieldPolicyNum.text = @"";
    self.fieldStartTime.text = @"";
    self.strStartTime = @"";
    self.fieldEndTime.text = @"";
    self.strEndTime = @"";
    self.fieldShipperInfo.text = @"";
    self.fieldDriverInfo.text = @"";
}
- (void)createTopView{

    CGRect rcFrame = CGRectMake(0, kTopHeight, [[UIScreen mainScreen] bounds].size.width, 0);
    FlexFrameView *header = [[FlexFrameView alloc] initWithFlex:@"SearchPolicyOrderListView" Frame:rcFrame Owner:self];
    header.flexibleHeight = YES;
    [header layoutIfNeeded];
    [self.view addSubview:header];
}

- (void)btnSaveInvoiceInfo{

    NSDictionary *dicPra = @{
                             @"policyNo":self.fieldPolicyNum.text,
                             @"mainOrderNumber":self.fieldSourcesOrderNum.text,
                             @"orderDetailNumber":self.fieldTranSportOrderNum.text,
                             @"gmtCreatedStart":self.strStartTime,
                             @"gmtCreatedEnd":self.strEndTime,
                             @"shipmentInfo":self.fieldShipperInfo.text,
                             @"driverInfo":self.fieldDriverInfo.text
                     };

    if (self.blockSerach) {
        self.blockSerach(dicPra);
        [self pop];
    }
}

- (void)btnSelectStartTimeAction{
    [self btnShowDataTimeWithType:@"0"];
}
- (void)btnSelectEndTimeAction{
    [self btnShowDataTimeWithType:@"1"];

}

- (void)btnShowDataTimeWithType:(NSString *)strType{
    
    WS(ws);
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]initWithPickerMode:BRDatePickerModeYMDHM];
    datePickerView.title = strType.intValue == 0 ? @"请选择开始时间":@"请选择截止时间";
    datePickerView.minDate = [NSDate br_setYear:2016 month:5 day:1];
    
    NSDate *datenow = [NSDate date];
    datePickerView.maxDate = datenow; //[NSDate br_setYear:2050 month:5 day:1];
    datePickerView.resultBlock = ^(NSString *selectValue) {
        if (strType.intValue == 0) {
            ws.fieldStartTime.text = CJStringWithFormat(@"%@:00",selectValue);
            ws.strStartTime = CJStringWithFormat(@"%@:00",selectValue);;
        } else {
            ws.fieldEndTime.text = CJStringWithFormat(@"%@:00",selectValue);;
            ws.strEndTime = CJStringWithFormat(@"%@:00",selectValue);;
        }
    };
    
    BRPickerStyle *customStyle = [BRPickerStyle pickerStyleWithThemeColor:[UIColor cjMainColor]];
    datePickerView.pickerStyle = customStyle;
    [datePickerView show];

}


@end
